# -*- coding: utf-8 -*-
"""
Created on Tue Jun 15 23:38:01 2021

@author: Lenovo
"""

import pygame,sys
from pygame.locals import *
import tkinter.messagebox
from tkinter import *
from pylab import mpl
import random
import time
import math
mpl.rcParams['font.sans-serif']=['SimHei']
mpl.rcParams['axes.unicode_minus']=False

# 精灵属性
ability=[[556,177,181,227,207,135],[524,213,147,213,147,221],[600,223,215,155,175,117],[560,217,181,187,177,189],[572,227,179,155,155,141]]
#技能优先级
skill_priority=[[0,0,0,2],[1,0,0,0],[0,0,0,0],[0,0,1,0],[0,0,0,0]]
#技能名称
skill=[['剑舞','虚张声势','高压水枪','深渊突袭'],['疯狂乱抓','全力一击','冥想','烈焰冲撞'],['光合作用','咬碎','超级吸取','飞叶风暴'],['冰晶寒甲','寒冰之力','天寒地冻','极冰烈闪'],['大地之力','地震','大地之墙','爆裂拳']]
#精灵
spirit=['伊优','小火猴','布布种子','柯蓝','莫比']
#精灵编号
dic={'伊优':0,'小火猴':1,'布布种子':2,'柯蓝':3,'莫比':4}
#属性克制
couter=[[0.5,2,0.5,1,2],[0.5,0.5,2,2,1],[2,0.5,0.5,1,2],[0.5,0.5,2,0.5,2],[1,2,0.5,1,1]]

#字体
def  drawText(content):
    pygame.font.init()
    font  =  pygame.font.SysFont('SimHei',30)
    text_sf  =  font.render(content,True,pygame.Color(0,255,0),pygame.Color(0,0,130))
    return  text_sf
#强化等级对应的强化数值
def f(state):
    lis=[]
    for i in range(len(state)):
        if state[i]>=0:
            lis.append((state[i]+2)/2)
        else:
            lis.append(2/(2-state[i]))
    return lis

#游戏帮助
def h():
    help_=Tk()
    help_.geometry('1200x800')
    help_.title('游戏帮助')
    help_message=Text(help_,height=800,width=1200)
    f=open(r'image\游戏帮助1.txt', encoding='utf-8', errors='ignore' )
    help_message.insert(1.0,f.read())
    help_message.pack()
    help_.mainloop()

#共20个技能
def f1_1(state1,state2,spirit1_health,spirit2_health,choice1,choice2,screen):
    state1[0]+=2
    screen.blit(drawText("%s 精灵的攻击大幅增强"%(spirit[choice1])),(400,400))
def f1_2(state1,state2,spirit1_health,spirit2_health,choice1,choice2,screen):
    state1[3]+=2
    screen.blit(drawText("%s 精灵的防御大幅增强"%(spirit[choice1])),(400,400))
def f1_3(state1,state2,spirit1_health,spirit2_health,choice1,choice2,screen):
    p=random.random()
    if p<=0.7:
        p1=random.random()
        if p1<=0.2:
            hit=2
            screen.blit(drawText("%s 精灵打出了致命一击"%(spirit[choice1])),(400,170))
        else:
            hit=1
    else:
        hit=0
        screen.blit(drawText("%s 精灵的技能没有命中"%(spirit[choice1])),(400,170))
    spirit2_health[0]-=hit*(120*ability[choice1][3]*f(state1)[1]*42/ability[choice2][4]/50*f(state2)[3]+2)*couter[choice1][choice2]*random.randint(217,255)/255
def f1_4(state1,state2,spirit1_health,spirit2_health,choice1,choice2,screen):
    p=random.random()
    if p<=0.8:
        p1=random.random()
        if p1<=0.2:
            hit=2
            screen.blit(drawText("%s 精灵打出了致命一击"%(spirit[choice1])),(400,170))
        else:
            hit=1
    else:
        hit=0
        screen.blit(drawText("%s 精灵的技能没有命中"%(spirit[choice1])),(400,170))
    spirit2_health[0]-=hit*(80*ability[choice1][1]*f(state1)[0]*42/ability[choice2][2]/50*f(state2)[2]+2)*couter[choice1][choice2]*random.randint(217,255)/255
def f2_1(state1,state2,spirit1_health,spirit2_health,choice1,choice2,screen):
    p=random.random()
    if p<=0.8:
        p1=random.random()
        if p1<=0.2:
            hit=2
            screen.blit(drawText("%s 精灵打出了致命一击"%(spirit[choice1])),(400,170))
        else:
            hit=1
    else:
        hit=0
        screen.blit(drawText("%s 精灵的技能没有命中"%(spirit[choice1])),(400,170))
    spirit2_health[0]-=hit*(25*random.randint(2,5)*ability[choice1][1]*f(state1)[0]*42/50/ability[choice2][2]*f(state2)[2]+2)*random.randint(217,255)/255
def f2_2(state1,state2,spirit1_health,spirit2_health,choice1,choice2,screen):
    p=random.random()
    if p<=0.8:
        p1=random.random()
        if p1<=0.2:
            hit=2
            screen.blit(drawText("%s 精灵打出了致命一击"%(spirit[choice1])),(400,170))
        else:
            hit=1
    else:
        hit=0
        screen.blit(drawText("%s 精灵的技能没有命中"%(spirit[choice1])),(400,170))
    spirit2_health[0]-=hit*(120*ability[choice1][1]*f(state1)[0]*42/50/ability[choice2][2]*f(state2)[2]+2)*random.randint(217,255)/255
def f2_3(state1,state2,spirit1_health,spirit2_health,choice1,choice2,screen):
    state1[0]+=1
    state2[0]+=1
    screen.blit(drawText("%s 精灵的攻击增强了"%(spirit[choice1])),(400,400))
    screen.blit(drawText("%s 精灵的特攻增强了"%(spirit[choice1])),(400,450))
def f2_4(state1,state2,spirit1_health,spirit2_health,choice1,choice2,screen):
    p=random.random()
    if p<=1:
        p1=random.random()
        if p1<=0.2:
            hit=2
            screen.blit(drawText("%s 精灵打出了致命一击"%(spirit[choice1])),(400,170))
        else:
            hit=1
    else:
        hit=0
        screen.blit(drawText("%s 精灵的技能没有命中"%(spirit[choice1])),(400,170))
    damage=hit*(125*ability[choice1][3]*f(state1)[1]*42/50/ability[choice2][4]*f(state2)[3]+2)*couter[choice1][choice2]*random.randint(217,255)/255
    spirit2_health[0]-=damage
    spirit1_health[0]-=0.25*damage

def f3_1(state1,state2,spirit1_health,spirit2_health,choice1,choice2,screen):
    spirit1_health[0]+=150
def f3_2(state1,state2,spirit1_health,spirit2_health,choice1,choice2,screen):
    p=random.random()
    if p<=0.8:
        p1=random.random()
        if p1<=0.2:
            hit=2
            screen.blit(drawText("%s 精灵打出了致命一击"%(spirit[choice1])),(400,170))
        else:
            hit=1
    else:
        hit=0
        screen.blit(drawText("%s 精灵的技能没有命中"%(spirit[choice1])),(400,170))
    spirit2_health[0]-=hit*(100*ability[choice1][1]*f(state1)[0]*42/50/ability[choice2][2]*f(state2)[2]+2)*random.randint(217,255)/255
    rd=random.random()
    if rd<=0.15 and hit==1:
        state2[2]-=2
        screen.blit(drawText("%s 精灵的防御下降了"%(spirit[choice2])),(400,450))

def f3_3(state1,state2,spirit1_health,spirit2_health,choice1,choice2,screen):
    p=random.random()
    if p<=1:
        p1=random.random()
        if p1<=0.2:
            hit=2
            screen.blit(drawText("%s 精灵打出了致命一击"%(spirit[choice1])),(400,170))
        else:
            hit=1
    else:
        hit=0
        screen.blit(drawText("%s 精灵的技能没有命中"%(spirit[choice1])),(400,170))
    damage=hit*(60*ability[choice1][3]*f(state1)[1]*42/50/ability[choice2][4]*f(state2)[3]+2)*couter[choice1][choice2]*random.randint(217,255)/255
    spirit2_health[0]-=damage
    spirit1_health[0]+=0.5*damage

def f3_4(state1,state2,spirit1_health,spirit2_health,choice1,choice2,screen):
    p=random.random()
    if p<=0.7:
        p1=random.random()
        if p1<=0.2:
            hit=2
            screen.blit(drawText("%s 精灵打出了致命一击"%(spirit[choice1])),(400,170))
        else:
            hit=1
    else:
        hit=0
        screen.blit(drawText("%s 精灵的技能没有命中"%(spirit[choice1])),(400,170))
    spirit2_health[0]-=hit*(140*ability[choice1][3]*f(state1)[1]*42/50/ability[choice2][4]*f(state2)[3]+2)*couter[choice1][choice2]*random.randint(217,255)/255
    state1[1]-=1
    screen.blit(drawText("%s 精灵的特攻下降了"%(spirit[choice1])),(400,500))

def f4_1(state1,state2,spirit1_health,spirit2_health,choice1,choice2,screen):
    state1[2]+=2
    state1[3]+=2
    screen.blit(drawText("%s 精灵的防御大幅增强"%(spirit[choice1])),(400,400))
    screen.blit(drawText("%s 精灵的特防大幅增强"%(spirit[choice1])),(400,450))
def f4_2(state1,state2,spirit1_health,spirit2_health,choice1,choice2,screen):
    state1[0]+=2
    screen.blit(drawText("%s 精灵的攻击力大幅增强"%(spirit[choice1])),(400,400))

def f4_3(state1,state2,spirit1_health,spirit2_health,choice1,choice2,screen):
    p=random.random()
    if p<=0.8:
        p1=random.random()
        if p1<=0.2:
            hit=2
            screen.blit(drawText("%s 精灵打出了致命一击"%(spirit[choice1])),(400,170))
        else:
            hit=1
    else:
        hit=0
        screen.blit(drawText("%s 精灵的技能没有命中"%(spirit[choice1])),(400,170))
    spirit2_health[0]-=hit*(100*ability[choice1][3]*f(state1)[1]*42/50/ability[choice2][4]*f(state2)[3]+2)*couter[choice1][choice2]*random.randint(217,255)/255
def f4_4(state1,state2,spirit1_health,spirit2_health,choice1,choice2,screen):
    p=random.random()
    if p<=0.7:
        p1=random.random()
        if p1<=0.2:
            hit=2
            screen.blit(drawText("%s 精灵打出了致命一击"%(spirit[choice1])),(400,170))
        else:
            hit=1
    else:
        hit=0
        screen.blit(drawText("%s 精灵的技能没有命中"%(spirit[choice1])),(400,170))
    spirit2_health[0]-=hit*(120*ability[choice1][1]*f(state1)[0]*42/50/ability[choice2][2]*f(state2)[2]+2)*couter[choice1][choice2]*random.randint(217,255)/255
def f5_1(state1,state2,spirit1_health,spirit2_health,choice1,choice2,screen):
    state1[0]+=2
    screen.blit(drawText("%s 精灵的攻击大幅增强"%(spirit[choice1])),(400,400))

def f5_2(state1,state2,spirit1_health,spirit2_health,choice1,choice2,screen):
    p=random.random()
    if p<=0.8:
        p1=random.random()
        if p1<=0.2:
            hit=2
            screen.blit(drawText("%s 精灵打出了致命一击"%(spirit[choice1])),(400,170))
        else:
            hit=1
    else:
        hit=0
        screen.blit(drawText("%s 精灵的技能没有命中"%(spirit[choice1])),(400,170))
    spirit2_health[0]-=hit*(100*ability[choice1][1]*f(state1)[0]*42/50/ability[choice2][2]*f(state2)[2]+2)*couter[choice1][choice2]*random.randint(217,255)/255
def f5_3(state1,state2,spirit1_health,spirit2_health,choice1,choice2,screen):
    state1[2]+=2
    screen.blit(drawText("%s 精灵的防御大幅增强"%(spirit[choice1])),(400,400))
def f5_4(state1,state2,spirit1_health,spirit2_health,choice1,choice2,screen):
    p=random.random()
    if p<=0.7:
        p1=random.random()
        if p1<=0.2:
            hit=2
            screen.blit(drawText("%s 精灵打出了致命一击"%(spirit[choice1])),(400,170))
        else:
            hit=1
    else:
        hit=0
        screen.blit(drawText("%s 精灵的技能没有命中"%(spirit[choice1])),(400,170))
    spirit2_health[0]-=hit*(120*ability[choice1][1]*f(state1)[0]*42/50/ability[choice2][2]*f(state2)[2]+2)*couter[choice1][choice2]*random.randint(217,255)/255
